package com.hpin.mlxteacher.my;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.hpin.mlxteacher.R;
import com.hpin.mlxteacher.base.BaseActivity;
import com.hpin.mlxteacher.utils.Constant;
//import com.umeng.analytics.MobclickAgent;

/**
 * 更改性别页面
 * Created by Aaron on 15/7/31.
 */
public class ChangeSexActivity extends BaseActivity {
    private final static int CHANGE_SEX_CODE = 10022;
    private ImageView cb_mal;
    private ImageView cb_femal;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_chage_sex);

        initWidget();

    }

    private void initWidget() {

        ImageView tv_left = (ImageView) findViewById(R.id.iv_left);
        TextView tv_title = (TextView) findViewById(R.id.tv_title);
        TextView tv_right = (TextView) findViewById(R.id.tv_right);

        tv_title.setText(getResources().getString(R.string.change_sex));
        tv_right.setText(getResources().getString(R.string.done));

        RelativeLayout rl_meal = (RelativeLayout) findViewById(R.id.rl_meal);
        RelativeLayout rl_femal = (RelativeLayout) findViewById(R.id.rl_femal);


        tv_left.setOnClickListener(this);
        tv_right.setOnClickListener(this);

        rl_meal.setOnClickListener(this);
        rl_femal.setOnClickListener(this);

        cb_mal = (ImageView) findViewById(R.id.cb_mal);
        cb_femal = (ImageView) findViewById(R.id.cb_femal);

        if ("女".equals(sp.getString(Constant.sex, ""))) {
            cb_mal.setSelected(false);
            cb_femal.setSelected(true);
        } else {
            cb_mal.setSelected(true);
            cb_femal.setSelected(false);

        }
    }


    @Override
    public void widgetClick(View v) {
        switch (v.getId()) {
            case R.id.iv_left:
                finish();
                break;
            case R.id.tv_right://完成


//                Intent data = new Intent();
//
//                data.putExtra("modifysex", cb_mal.isSelected() ? 1 : 0);
//
//                setResult(CHANGE_SEX_CODE, data);
//
//                finish();
//                SharedPreferences.Editor editor= sp.edit();
//
//                editor.putString(Constant.sex,cb_mal.isSelected() ? "男" : "女");
//                editor.apply();

                Intent data = new Intent();
                data.putExtra("modifysex", cb_mal.isSelected() ? "男" : "女");
                setResult(CHANGE_SEX_CODE, data);

                finish();
                break;
            case R.id.rl_meal:

                cb_mal.setSelected(true);
                cb_femal.setSelected(false);

                break;
            case R.id.rl_femal:

                cb_mal.setSelected(false);
                cb_femal.setSelected(true);


                break;

        }
    }

//    public void onResume() {
//        super.onResume();
//        MobclickAgent.onResume(this);       //统计时长
//    }
//
//    public void onPause() {
//        super.onPause();
//        MobclickAgent.onPause(this);
//    }
}
